/*******************************************************************
 *
 * Copyright (C), 2021-2022, LS, All rights reserved.
 *
 * Author      : 
 * Create Time : 2020-12-25
 * Version     : v0.1
 * Description : 
 *******************************************************************/
 
/*----------------------------Head file----------------------------*/
#include "wm.h"
#include "string.h"
#include "app_reset.h"
#include "app_skip_alg.h"
#include "app_global_data.h"
#include "user_config.h"

/*----------------------------macro file---------------------------*/

/*----------------------------type define--------------------------*/

/*----------------------------var define---------------------------*/
static uint8_t ota_process_cnt = 0;

/*-------------------------func declaration------------------------*/

/*-----------------------------------------------------------------*/

static void ota_ing_disp_1hz_update(void)
{
    if(ota_process_cnt < 4) {
        ota_process_cnt++;
    }
    else {
        ota_process_cnt = 0;
    }
    app_disp_ota_ing(ota_process_cnt);
}


void wm_ota_ing_disp(void)
{
    wm_t wm;

    memset(&wm, 0, sizeof(wm));
    wm.cur_win = OTA_ING_WIN;
    wm.disp_off_cnt = DISP_NEVER_OFF_CNT;
    wm.auto_update_1hz_cb = ota_ing_disp_1hz_update;

    wm_info_set(&wm);

    app_skip_mode_set(SKIP_MODE_NULL);

    ota_process_cnt = 0;
    app_disp_clear();
    app_disp_ota_ing(ota_process_cnt);
    app_disp_bt_icon();
    app_disp_update();

    app_disp_backlight_set(true);
}


static void reset_cb(void)
{
    app_system_reset();	//reset with utc revert.
}

static void ota_done_disp_1hz_update(void)
{
    if(ota_process_cnt < 2) {
        ota_process_cnt++;
    }
    else {
        app_system_reset();
        ota_process_cnt = 0;
    }
}

void wm_ota_done_disp(void)
{
    wm_t wm;

    memset(&wm, 0, sizeof(wm));
    wm.cur_win = OTA_DONE_WIN;
    wm.short_press_cb = reset_cb;
    wm.auto_update_1hz_cb = ota_done_disp_1hz_update;
    wm.disp_off_cnt = DISP_NEVER_OFF_CNT;

    wm_info_set(&wm);

    ota_process_cnt = 0;
    app_disp_clear();
    app_disp_done();
    app_disp_bt_icon();
    app_disp_update();

    wm_set_backlight_off_cnt(DISP_NEVER_OFF_CNT);
    app_disp_backlight_set(true);
}


void wm_ota_fail_disp(void)
{
    wm_t wm;

    memset(&wm, 0, sizeof(wm));
    wm.cur_win = OTA_FAIL_WIN;
    wm.short_press_cb = reset_cb;
    wm.disp_off_cnt = DISP_NEVER_OFF_CNT;

    wm_info_set(&wm);

    app_disp_clear();
    app_disp_fail();
    app_disp_bt_icon();
    app_disp_update();

    wm_set_backlight_off_cnt(DISP_NEVER_OFF_CNT);
    app_disp_backlight_set(true);
}

